<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客正文</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="js/tools.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/doge.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="javascript:onExit()"> 退出登陆</a>     
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="img/doge.jpg" class="avtar" alt="">
                <h3 id="username"></h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span id="wengzhang"></span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="blog-content">
                <!-- 博客标题 -->
                <h3 id="title"></h3>
                <!-- 博客时间 -->
                <div class="date">
                    <span id ="data"></span>&nbsp;&nbsp;&nbsp;阅读量:
                    <span id ="rcount"></span>
                </div>
                <div id="rcount" class="date"></div> 
                <!-- 博客正文 -->
                <div id="editorDiv">
                </div>
            </div>
        </div>
    </div>
</body>
<script >
   
   function onExit(){
        if(confirm("确认退出?")){
            // alert("退出成功");
            jQuery.ajax({
                url:"/user/logout",
                type:"POST",
                data:{},
                success:function(result){
                    location.href="/login.html";
                },
                error:function(err){
                    if(err!=null&&err.status==401){
                       // alert(JSON.stringify(err));
                       alert("用户未登陆");
                       location.href="/login.html";
                    }      
                }
            });
        }
     }
    function getURLParam(key){
        var params=location.search;
        if(params.indexOf("?")>=0){
            params=params.substring(params.indexOf("?")+1);
            var paramArr=params.split('&');
            for(var i=0;i<paramArr.length;i++){
                var namevalues=paramArr[i].split("=");
                if(namevalues[0]==key){
                    return namevalues[1];
                }
            }
        }else{
            return "";
        }
    }
    function getT(uid){
        var total=1;
        jQuery.ajax({
            url:"/art/gett",
            type:"POST",
            data:{
                "uid":uid
            },
            success:function(result){
                if(result.code==200&&result.data!=null){
                    total=result.data;
                    jQuery("#wengzhang").text(total);
                }
            }
        });
    }
    function myInfo(id){
     jQuery.ajax({
          url:"/user/myinfo2",
          type:"POST",
          data:{"id":id},
          success:function(result){
              if(result.code==200&&result.data!=null){
                  jQuery("#username").text(result.data.username);
                  getT(result.data.id);
              }
          }
      });
   }
    function getArtDetail(){
        var aid=getURLParam("id");
        if(aid!=null&&aid>0){
            jQuery.ajax({
                url:"/art/detail",
                type:"POST",
                data:{"aid":aid},
                success:function(result){
                    if(result.code==200&&result.data!=null){
                        jQuery("#title").text(result.data.title);
                        jQuery("#data").text(result.data.createtime);
                        jQuery("#rcount").text(result.data.rcount);
                        editormd=editormd.markdownToHTML("editorDiv",{
                            markdown:result.data.content
                        });
                        myInfo(result.data.uid);
                    }
                }
            });
        }
    }
    getArtDetail(); 
</script> 
</html>